
addpath('gpml-matlab-v3.1-2010-09-27');
addpath('Netlab');
startup;

gendata([0.6;0.6]); % or whatever
dim = 2; % for ISO
n_expts = 5;

cov_func = @covSEiso;
D = load('gp_data'); % much of this is CVed from cross_validate.m
dim = size(D);
n = size(D,1);
dim = dim(2)-1; % i.e. data are from a dim-dimensional space; the -1 is not counting the class label
n_class = max(D(:,dim+1));

X = D(:,1:dim);
y1 = D(:,dim+1);
y = reshape(kron(ones(n,1),1:n_class),n*n_class,1)==repmat(y1,n_class,1); % expressed as 1-of-n_class encoding

K = zeros(n,n,n_class);sigma_noise = 1e-7;
hyps = load('gp_hyps')'; hyps = reshape(hyps, 1, n_class*dim);
for c = 1:n_class
  K(:,:,c) = cov_func(hyps(c*2-1:c*2), X, X) + sigma_noise*eye(n); % hax
end  
%approxF = alg_3_3(n, n_class, K, y);
approxF = zeros(n*n_class,1);
dels = zeros(n_expts, dim*n_class);

for gci = 1:n_expts
  hyps = repmat([0.2 * (0.5 * (n_expts + 1) - gci); 0], n_class, 1)';
  fprintf('Performing gradchek %i\n', gci);
  [grad, del] = gradchek(hyps, @log_det_B, @del_log_det_B, cov_func, n, n_class, X, y, approxF);
  dels(gci, :) = del;
end
%clf;
%hist(dels(:));